package com.hongshan.wallet.core

import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import com.hongshan.wallet.R
import com.hongshan.wallet.base.SimpleTextWatcher
import com.hongshan.wallet.util.goSetPwd
import kotlinx.android.synthetic.main.dialog_input_pwd.view.*

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core
 * @author   : zhangxx
 * @date     : 2019/3/27
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */
class InputPwdDialogFragment() : DialogFragment() {

    var action:String = "提现"
    var money:String = ""

    var contentView: View? = null

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_input_pwd, null)
        this.contentView = view;
        val dialog = AlertDialog.Builder(context!!)
            .setView(view)
            .create()
        view.ivClose.setOnClickListener { dismiss() }
        view.pwe.addTextChangedListener(SimpleTextWatcher {
            if (it.length == 6){
                inputComplete?.invoke(it)
            }
        })
        view.tvAction.text = action
        view.tvMoney.text = money
        view.tvForgetPwd.setOnClickListener { goSetPwd() }
        return dialog
    }

    var inputComplete: ((String) -> Unit)? = null

    fun cleanPwd(){
        contentView?.pwe?.setText("")
    }
}